package com.tx.studentManager.service;

import java.util.Date;
import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import com.tx.studentManager.dao.UrlFilterDao;
import com.tx.studentManager.model.UrlFilter;
import com.tx.studentManager.qo.UrlFilterQO;

/**
 * 
 【UrlFilter Service】
 * 
 * @since studentManager-admin 1.0.2
 * @version 1.0.2
 * @date 2015年9月27日 上午9:14:04
 * @author 此生唯晴
 */
@Transactional
@Service
public class UrlFilterService extends
		BaseService<UrlFilter, String, UrlFilterDao, UrlFilterQO> {
	@Autowired
	private UrlFilterDao urlFilterDao;
	@Autowired(required=false)
	private ShiroFilterChainService shiroFilerChainService;

	@Override
	protected UrlFilterDao getDao() {
		return urlFilterDao;
	}

	public void initFilterChain() {
		shiroFilerChainService.initFilterChains(findAllActived());
	}
	/**
	 * 
	* @描述 查询所有可用的权限规则 
	* @return
	 */
	public List<UrlFilter> findAllActived(){
		UrlFilterQO qo =new UrlFilterQO();
		qo.setIsActived(1);
		return list(qo);
	}
	
	@Override
	public UrlFilter insert(UrlFilter urlFilter) {
		if (urlFilter.getCreateDate() == null) {
			urlFilter.setCreateDate(new Date());
		}
		urlFilter = super.insert(urlFilter);
		initFilterChain();
		return urlFilter;
	}

	@Override
	public boolean delete(String id) {
		boolean result = super.delete(id);
		initFilterChain();
		return result;
	}

	@Override
	public boolean update(UrlFilter urlFilter) {
		boolean result = super.update(urlFilter);
		initFilterChain();
		return result;
	}

}
